import 'package:bookshelf/data.dart';
import 'package:bookshelf/rating_bar.dart';
import 'package:flutter/material.dart';

class Detail extends StatelessWidget {
  final Book book;
  Detail(this.book);

  @override
  Widget build(BuildContext context) {
    //app bar
    final appBar = new AppBar(
      elevation: .5,
      title: new Text("Book Shelf"),
      actions: <Widget>[
        new IconButton(
          icon: new Icon(Icons.search),
          onPressed: () {},
        ),
      ],
    );

    //detail of book image and it's pages
    final topLeft = new Column(
      children: <Widget>[
        new Padding(
          padding: new EdgeInsets.all(16.0),
          child: new Hero(
              tag: book.title,
              child: new Material(
                elevation: 15.0,
                shadowColor: Colors.yellow.shade900,
                child: new Image(
                  image: new AssetImage(book.image),
                  fit: BoxFit.cover,
                ),
              )),
        ),
        text('${book.pages} pages', color: Colors.black38, size: 12),
      ],
    );

    //detail top right
    final topRight = new Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        text(book.title,
            size: 16, isBold: true, padding: new EdgeInsets.only(top: 16.0)),
        text('by ${book.writer}',
            color: Colors.black54,
            size: 12,
            padding: new EdgeInsets.only(top: 8.0, bottom: 16.0)),
        new Row(
          children: <Widget>[
            text(book.time,
                isBold: true, padding: new EdgeInsets.only(right: 8.0)),
            new RatingBar(rating: double.parse(book.rating) / 2.0),
          ],
        ),
        new SizedBox(height: 32.0),
        new Material(
          borderRadius: new BorderRadius.circular(20.0),
          shadowColor: Colors.blue.shade200,
          elevation: 5.0,
          child: new MaterialButton(
            onPressed: () {},
            minWidth: 180.0,
            color: Colors.blue,
            child: text('BUY IT NOW', color: Colors.white, size: 13),
          ),
        ),
      ],
    );

    // topContent
    final topContent = new Container(
      color: Theme.of(context).primaryColor,
      padding: new EdgeInsets.only(bottom: 15.0),
      child: new Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          new Flexible(
            child: topLeft,
            flex: 2,
          ),
          new Flexible(
            child: topRight,
            flex: 3,
          ),
        ],
      ),
    );

    // scrolling text description
    final bottomContent = new Expanded(
      child: new SingleChildScrollView(
        padding: new EdgeInsets.all(16.0),
        child: text(book.description, size: 13.0),
      ),
    );

    return new Scaffold(
      appBar: appBar,
      body: new Column(
        children: <Widget>[
          topContent,
          bottomContent,
        ],
      ),
    );
  }

  text(String data,
          {Color color = Colors.black87,
          num size = 14,
          EdgeInsetsGeometry padding = EdgeInsets.zero,
          bool isBold = false}) =>
      new Padding(
        padding: padding,
        child: new Text(
          data,
          style: new TextStyle(
            color: color,
            fontSize: size.toDouble(),
            fontWeight: isBold ? FontWeight.bold : FontWeight.normal,
          ),
        ),
      );
}
